﻿
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace SpeedSearch
{
    /// <summary>
    /// Fournit les éléments graphiques de la virtualisation
    /// </summary>
    public class VirtualizationWrapper
    {
        private Config _config = Config.GetInstance();

        public GroupBox GenericGroupBox { get; set; }

        public List<VirtualizationWorkUnit> VirtualizationWorkUnits { get; set; }

        public VirtualizationWrapper(Control parentControl, ImageList mainFormImageList)
        {
            // Création du groupBox contenant
            this.GenericGroupBox = new GroupBox()
            {
                Dock = DockStyle.Fill,
                Text = "Gestion de la virtualisation de dossiers",
            };

            // Création des unités de virtualisation
            this.VirtualizationWorkUnits = new List<VirtualizationWorkUnit>()
            {
                new VirtualizationWorkUnit()
                {
                    AssociatedConfig = this._config.Virtualization[0],
                    AssociatedTextBox = new VirtualizationTextBox()
                    {
                        Location = new Point(10, 25),
                        Size = new Size(parentControl.Width * 75 / 100, 24)
                    },
                    AssociatedStatePictureBox = new VirtualizationPictureBox(mainFormImageList)
                    {
                        Location = new Point(parentControl.Width * 75 / 100 + 30, 25)
                    },
                    AssociatedWorkPictureBox = new VirtualizationPictureBox(mainFormImageList)
                    {
                        Location = new Point(parentControl.Width * 75 / 100 + 55, 25)                 
                    }
                },
                new VirtualizationWorkUnit()
                {
                    AssociatedConfig = this._config.Virtualization[1],
                    AssociatedTextBox = new VirtualizationTextBox()
                    {
                        Location = new Point(10, 60),
                        Size = new Size(parentControl.Width * 75 / 100, 24)
                    },
                    AssociatedStatePictureBox = new VirtualizationPictureBox(mainFormImageList)
                    {
                        Location = new Point(parentControl.Width * 75 / 100 + 30, 60)
                    },
                    AssociatedWorkPictureBox = new VirtualizationPictureBox(mainFormImageList)
                    {
                        Location = new Point(parentControl.Width * 75 / 100 + 55, 60)              
                    }
                },
                new VirtualizationWorkUnit()
                {
                    AssociatedConfig = this._config.Virtualization[2],
                    AssociatedTextBox = new VirtualizationTextBox()
                    {
                        Location = new Point(10, 95),
                        Size = new Size(parentControl.Width * 75 / 100, 24)
                    },
                    AssociatedStatePictureBox = new VirtualizationPictureBox(mainFormImageList)
                    {
                        Location = new Point(parentControl.Width * 75 / 100 + 30, 95)
                    },
                    AssociatedWorkPictureBox = new VirtualizationPictureBox(mainFormImageList)
                    {
                        Location = new Point(parentControl.Width * 75 / 100 + 55, 95)              
                    }
                }
            };

            // Affectation des controls au groupBox
            foreach (var wU in this.VirtualizationWorkUnits)
            {
                wU.UpdateWorkUnitFromState();
                wU.AssociatedControlsToParent(this.GenericGroupBox);
            }

            // Affectation du groupBox au contrôle parent
            parentControl.Controls.Add(this.GenericGroupBox);
        }

        public void Show()
        {
            GenericGroupBox.Show();
        }

        public void Hide()
        {
            GenericGroupBox.Hide();
        }
    }
}
